<?php
    if(!$this->session->userdata('logged_in')) {
        redirect('logout');
    } else if($this->session->userdata('role') !== 'admin') {
        redirect('forbidden');
    }
?>
<div id="uploaded_emp_page">
    <div id="uploaded_emp_wrapper">
        <?php echo form_open('register/employee', array('id' => 'uploaded_emp_form')); 
          if(sizeof($csvData) === 0) {
              $this->session->set_flashdata('message', 'The csv file does not contain any valid account.');
              redirect(base_url().'users/upload', 'refresh');
          } else {?>
          <label class="uploaded_note">Note: A row's check box is disabled if it contains an ID Number that is already registered in the database.</label>
          <table id="uploaded_emp_table">
            <th id ="checked">Register?</th>
            <th>ID Number</th>
            <th>Last Name</th>
            <th>First Name</th>
            <th>Middle Name</th>
            <th>Email Address</th>
            <th>Department</th>
          <?php
              $x = 0;
              foreach($csvData as $field){?>
                <tr>
                <?php           
                  $exists = $this->user_m->user_exists($field['idno']);

                  // checks if ID Number exists in the database
                  if($exists) {
                      echo "<td id=checked><input disabled type=checkbox name=user[] value=" . $x . "/></td>";
                  } else {
                      $fvalue = str_replace(" ","???",$field['idno'] . "," . $field['lname'] . "," . $field['fname'] . "," . $field['mname'] . "," . $field['email'] . "," . $field['department']);
                      echo "<td id=checked><input checked type=checkbox name=user[] value=" . $fvalue . "/></td>";
                  }
                ?>
                <td><?=$field['idno']?></td>
                <td><?=$field['lname']?></td>
                <td><?=$field['fname']?></td>
                <td><?=$field['mname']?></td>
                <td><?=$field['email']?></td>
                <td><?=$field['department']?></td>
                </tr>

          <?php 
                $x++;    
              }?>

              </table><br/>
          <input type="submit" value="Register" id="btn_cancel" />
          <input type="button" id="btn_cancel" value="Cancel" onclick="window.location='<?php echo base_url() ?>user/upload_file';" />
          <?php }?>
        <?php echo form_close() ?>
    </div>
</div>